package com.jiezuo.flowable.mapper;

import com.jiezuo.common.util.StringUtil;

/**
 * @author 庞留杰
 * @version V1.0
 * @description
 * @date 2020/8/24 13:42
 **/
public class MyProvider {

    public String findUsersAndButtonIds(String filter) {
        StringBuilder sb = new StringBuilder();
        sb.append("SELECT * FROM " +
                "            ( SELECT " +
                "                su.id AS user_id, " +
                "                su.user_code, " +
                "                su.user_name, " +
                "                su.real_name, " +
                "                su.password, " +
                "                su.email, " +
                "                (SELECT GROUP_CONCAT(sur.role_id)FROM sys_user_role sur WHERE sur.user_id=su.id) AS role_ids , " +
                "                (SELECT GROUP_CONCAT(DISTINCT sp.id) FROM sys_role_permission srp " +
                "                    LEFT JOIN sys_permission sp ON srp.permission_id=sp.id " +
                "                    LEFT JOIN sys_user_role sur ON sur.role_id=srp.role_id " +
                "                    WHERE sp.link_type=1 AND sur.user_id=su.id " +
                "                ) AS button_ids " +
                "            FROM sys_user_view su " +
                "            WHERE su.is_delete=0 " +
                "           ) a " +
                "        WHERE 1=1 ");
        if (StringUtil.isNotEmpty(filter)) {
            sb.append("AND a.real_name LIKE concat('%','" + filter + "','%') ");
        }
        return sb.toString();
    }


    public String findButtons(String filter) {
        StringBuilder sb = new StringBuilder();
        sb.append("SELECT  " +
                " sp.*  " +
                "FROM sys_permission sp  " +
                "WHERE sp.is_delete=0 AND sp.link_type=1 ");
        if (StringUtil.isNotEmpty(filter)) {
            sb.append("AND( sp.resource_name LIKE concat('%','" + filter + "','%') ");
            sb.append("OR sp.description LIKE concat('%','" + filter + "','%') )");
        }
        return sb.toString();
    }

}
